﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace KaiXin001er
{
    public partial class DebugWindow : Form
    {
        public DebugWindow()
        {
            InitializeComponent();
        }
        public delegate void showMsg(string msg);
        public void onMessage(object o, EventArgs msg)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new showMsg(writeMsg2window), new object[] { msg.ToString() });
            }
            else
            {
                writeMsg2window(msg.ToString());
            }
        }
        public void writeMsg2window(string msg)
        {
            Trace.Tracer.trace(msg);
            this.richTextBox1.AppendText(msg.ToString() + "   ["+DateTime.Now.ToString()+"]\r\n");
        }
        public void startDebuger()
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new windowOper(startDebuger));
            }
            else
            {
               // this.ShowDialog();
                this.Show();
            }
        }
        private delegate void windowOper();
        public void endDebuger()
        {

            if (this.InvokeRequired)
            {

                this.Invoke(new windowOper(endDebuger));
            }
            else
            {
                if (OnStopNormal != null) OnStopNormal();
                this.Dispose();
            }
        }

        public delegate void StopForce();
        public StopForce OnStopForce;
        public delegate void StopNormal();
        public StopNormal OnStopNormal;
        private void btn_stop_Click(object sender, EventArgs e)
        {
            if (OnStopForce != null) OnStopForce();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            btn_stop_Click(sender, e);
            this.endDebuger();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.richTextBox1.ZoomFactor++;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (this.richTextBox1.ZoomFactor == 1) return;
            this.richTextBox1.ZoomFactor--;
        }


        ///实现移动的代码
        ///
        Point currentPt;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void richTextBox1_MouseDown(object sender, MouseEventArgs e)
        {

            currentPt = Cursor.Position;

        }

        private void richTextBox1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                int px = Cursor.Position.X - currentPt.X;
                int py = Cursor.Position.Y - currentPt.Y;
                this.Location = new Point(this.Location.X + px, this.Location.Y + py);
                currentPt = Cursor.Position;
            } 

        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Maximized;
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Normal;
        }



        
    }
}
